package com.jinmdz.fmis.dao.dao;

import com.jinmdz.fmis.dao.dao.provider.TransportTaskPorterProvider;
import com.jinmdz.fmis.dao.model.transport.TransportCodeText;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

/**
 * 接运抬尸工Dao
 *
 * @author LiCongLu
 * @date 2020-02-13 10:43
 */
public interface TransportTaskPorterDao {

    /**
     * 按照抬尸工主键集合
     *
     * @param transportTaskId 接运任务主键
     * @return
     * @author LiCongLu
     * @date 2020-02-13 13:44
     */
    @Select(" select system_user_id from transport_task_porter " +
            " where transport_task_id = #{transportTaskId} and deleted = 0")
    @ResultType(Integer.class)
    ArrayList<Integer> listSystemUserIdByTransportTaskId(@Param("transportTaskId") Integer transportTaskId);

    /**
     * 清除指定接运任务的抬尸工信息
     *
     * @param transportTaskId 接运任务主键
     * @param modifiedUserId  修改用户外键
     * @return
     * @author LiCongLu
     * @date 2020-02-13 10:46
     */
    @Update(" update transport_task_porter set deleted = 1,modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where transport_task_id = #{transportTaskId} and unmodified = 0 and deleted = 0 ")
    void deletedForTransportTaskPorter(@Param("transportTaskId") Integer transportTaskId, @Param("modifiedUserId") Integer modifiedUserId);

    /**
     * 批量逻辑删除接运任务的尸工信息
     *
     * @param transportTaskId 接运任务主键
     * @param modifiedUserId  修改用户外键
     * @param userIds         要删掉的抬尸工
     * @return
     * @author LiCongLu
     * @date 2020-02-13 15:36
     */
    @UpdateProvider(type = TransportTaskPorterProvider.class, method = "deletedForTransportTaskPorterByUserIds")
    void deletedForTransportTaskPorterByUserIds(@Param("transportTaskId") Integer transportTaskId, @Param("modifiedUserId") Integer modifiedUserId, @Param("userIds") ArrayList<Integer> userIds);

    /**
     * 按照抬尸工主键和名称对照集合
     *
     * @param transportTaskId 接运任务主键
     * @return
     * @author GaoXiangLiang
     * @date 2020-05-14 13:44
     */
    @Select(" select distinct transport_task_porter.system_user_id AS id,system_user.full_name AS fullName from transport_task_porter  join system_user   on transport_task_porter.system_user_id=system_user.id" +
            " where transport_task_porter.transport_task_id = #{transportTaskId} ")
    @ResultType(TransportCodeText.class)
    ArrayList<TransportCodeText> listSystemUserIdAndTextByTransportTaskId(@Param("transportTaskId") Integer transportTaskId);
}
